package leetcode.code0541;

public class Solution {
	public String reverseStr(String s, int k) {
		if (k == 1) {
			return s;
		}
		char[] cs = s.toCharArray();
		for (int i = 0; i < cs.length; i += k << 1) {
			int l = i, r = i + k >= cs.length ? cs.length - 1 : i + k - 1;
			if (r < cs.length) {
				while (l < r) {
					char c = cs[l];
					cs[l] = cs[r];
					cs[r] = c;
					l++;
					r--;
				}
			}
		}
		return new String(cs);
	}
}
